import type { FileEntity } from '@/entity/BaseEntity.ts';
import http from '@/utils/http';
import { type _AxiosRequestConfig, MULTIPART_FORM_DATA } from '@/utils/http/types';

const deptBaseUrl = '/system/dept';
const postBaseUrl = '/system/post';
const userBaseUrl = '/system/user';

/*========================部门=============================*/
// 列表
export const ApiDeptList = (data: any, options?: _AxiosRequestConfig) => http.get<any>(`${deptBaseUrl}/tree`, data, options)
// 新增
export const ApiDeptAdd = (data: any, options?: _AxiosRequestConfig) => http.post<any>(`${deptBaseUrl}/create`, data, options);

// 修改
export const ApiDeptUpdate = (data: any, options?: _AxiosRequestConfig) => http.put<any>(`${deptBaseUrl}/update`, data, options);

// 删除
export const ApiDeptDelete = (params: any, options?: _AxiosRequestConfig) => http.delete<any>(`${deptBaseUrl}/delete`, params, options);

// 设置部门负责人
export const ApiManager = (id: number, params: any, options?: _AxiosRequestConfig) => http.put<any>(`${deptBaseUrl}/${id}/manager-update`, params, options);

/*========================岗位=============================*/
// 列表
export const ApiPostList = (params: any, options?: _AxiosRequestConfig) => http.get<any>(`${postBaseUrl}/list`, params, options);

// 列表-分页
export const ApiPostPage = (params: any, options?: _AxiosRequestConfig) => http.get<any>(`${postBaseUrl}/page`, params, options);

// 新增
export const ApiPostAdd = (data: any, options?: _AxiosRequestConfig) => http.post<any>(`${postBaseUrl}/create`, data, options);

// 修改
export const ApiPostUpdate = (data: any, options?: _AxiosRequestConfig) => http.put<any>(`${postBaseUrl}/update`, data, options);

// 删除
export const ApiPostDelete = (params: any, options?: _AxiosRequestConfig) => http.delete<any>(`${postBaseUrl}/delete`, params, options);

/*========================用户=============================*/
// 列表
export const ApiUserPage = (params: any, options?: _AxiosRequestConfig) => http.get<any>(`${userBaseUrl}/page`, params, options);

// 所有用户-精简
export const ApiUserList = (options?: _AxiosRequestConfig) => http.get<any>(`/system/user/simple-list`, undefined, options);

// 新增
export const ApiUserAdd = (data: any, options?: _AxiosRequestConfig) => http.post<any>(`${userBaseUrl}/create`, data, options);

// 修改
export const ApiUserUpdate = (data: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/update`, data, options);

// 删除
export const ApiUserDelete = (params: any, options?: _AxiosRequestConfig) => http.delete<any>(`${userBaseUrl}/delete`, params, options);

// 恢复
export const ApiUserEnable = (id: number, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${id}/enable`, undefined, options);

// 修改用户密码
export const ApiUserPassword = (params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${params.id}/password-update`, params, options);

// 重置用户密码
export const ApiResetPassword = (params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${params.id}/reset/password`, params, options);

// 离职
export const ApiUserDisable = (params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${params.id}/disable`, params, options);

// 岗位下的用户
export const ApiUserPost = (params: any, options?: _AxiosRequestConfig) => http.get<any>(`${userBaseUrl}/list`, params, options);

// 移出成员
export const ApiUserPostRemove = (params: any, options?: _AxiosRequestConfig) => http.delete<any>(`${userBaseUrl}/post/remove`, params, options);

// 添加成员
export const ApiUserPostAdd = (data: any, options?: _AxiosRequestConfig) => http.post<any>(`${userBaseUrl}/post/add`, data, options);

// 调动部门
export const ApiUserChangeDept = (params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${params.deptId}/transfer`, params, options);

// 修改-用户名
export const ApiUserNameUpdate = (id: number, params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${id}/name-update`, params, options);

// 修改-手机号
export const ApiUserMobileUpdate = (id: number, params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${id}/mobile-update`, params, options);

// 修改-邮箱
export const ApiUserEmailUpdate = (id: number, params: any, options?: _AxiosRequestConfig) => http.put<any>(`${userBaseUrl}/${id}/email-update`, params, options);

/*========================文件上传=============================*/
// 上传文件
export const ApiUpload = (data: any, options?: _AxiosRequestConfig) => http.post<FileEntity>(`/oss/file/upload`, data,
	{
		...options,
		headers: {
			'Content-Type': MULTIPART_FORM_DATA,
		},
	}
);

// 上传文件
export const ApiUploadMini = (data: any, options?: _AxiosRequestConfig) => http.post<any>(`/oss/file/upload-image`, data,
	{
		...options,
		headers: {
			'Content-Type': MULTIPART_FORM_DATA,
		},
	}
);

// 文件-下载
export const ApiUploadUrl = (params: any, options?: _AxiosRequestConfig) => http.get<any>(`/oss/file/get`, params, options);

// 文件-获取文件
export const ApiFileGet = (id: number, options?: _AxiosRequestConfig) => http.get<any>(`/oss/file/${id}/get`, undefined, options);

// 文件-删除-id
export const ApiFileDelete = (id: number, options?: _AxiosRequestConfig) => http.delete<any>(`/oss/file/${id}/delete`, undefined, options);

// 文件-重命名
export const ApiFileRename = (id: number, params: any, options?: _AxiosRequestConfig) => http.put<any>(`/oss/file/${id}/update`, params, options);

/*-------------------------------自定义字段--------------------------------------*/
// 列表
export const ApiFieldsList = (params: any, options?: _AxiosRequestConfig) => http.get<any>(`/crm/project/biz-config`, params, options);
